﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Xml.Serialization;

namespace GTA.BusinessEntity.Configuration
{
    [Serializable()]
    public class SearchFilter : ISerializable
    {
        public SearchFilter()
        {
            Category = new List<DomainFilter>();
            DesignedTo = new List<UserFilter>();
            Project = new List<ProjectFilter>();
            State = new List<DomainFilter>();
        }
        public SearchFilter(BusinessEntity.TaskFilter filter)
            : this()
        {
            this.ID = filter.ID;
            this.ScheduleEstimatedEndFrom = filter.ScheduleEstimatedEndFrom;
            this.ScheduleEstimatedEndTo = filter.ScheduleEstimatedEndTo;
            this.ScheduleEstimatedStartFrom = filter.ScheduleEstimatedStartFrom;
            this.ScheduleEstimatedStartTo = filter.ScheduleEstimatedStartTo;
            this.ScheduleRealizedEndFrom = filter.ScheduleRealizedEndFrom;
            this.ScheduleRealizedEndTo = filter.ScheduleRealizedEndTo;
            this.ScheduleRealizedStartFrom = filter.ScheduleRealizedStartFrom;
            this.ScheduleRealizedStartTo = filter.ScheduleRealizedStartTo;

            if (filter.Category != null)
                filter.Category.ForEach(it => this.Category.Add(new GTA.BusinessEntity.Configuration.DomainFilter()
                {
                    Description = it.Description,
                    ID = it.ID
                }));
            if (filter.DesignedTo != null)
                filter.DesignedTo.ForEach(it => this.DesignedTo.Add(new GTA.BusinessEntity.Configuration.UserFilter()
                {
                    Name = it.Name
                }));
            if (filter.Project != null)
                filter.Project.ForEach(it => this.Project.Add(new GTA.BusinessEntity.Configuration.ProjectFilter()
                {
                    Id = it.Id,
                    Name = it.Name
                }));
            if (filter.State != null)
                filter.State.ForEach(it => this.State.Add(new GTA.BusinessEntity.Configuration.DomainFilter()
                {
                    ID = it.ID,
                    Description = it.Description
                }));
        }

        [XmlElement("ID")]
        public Int32 ID;
        [XmlElement("Category")]
        public List<DomainFilter> Category;
        [XmlElement("DesignedTo")]
        public List<UserFilter> DesignedTo;
        [XmlElement("Project")]
        public List<ProjectFilter> Project;
        [XmlElement("State")]
        public List<DomainFilter> State;
        [XmlElement("ScheduleEstimatedStartFrom")]
        public DateTime ScheduleEstimatedStartFrom;
        [XmlElement("ScheduleEstimatedStartTo")]
        public DateTime ScheduleEstimatedStartTo;
        [XmlElement("ScheduleEstimatedEndFrom")]
        public DateTime ScheduleEstimatedEndFrom;
        [XmlElement("ScheduleEstimatedEndTo")]
        public DateTime ScheduleEstimatedEndTo;
        [XmlElement("ScheduleRealizedStartFrom")]
        public DateTime ScheduleRealizedStartFrom;
        [XmlElement("ScheduleRealizedStartTo")]
        public DateTime ScheduleRealizedStartTo;
        [XmlElement("ScheduleRealizedEndFrom")]
        public DateTime ScheduleRealizedEndFrom;
        [XmlElement("ScheduleRealizedEndTo")]
        public DateTime ScheduleRealizedEndTo;

        #region ISerializable Members

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
